<%--
@author Kusal Samarakoon
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<script type="text/javascript">


    $(function() {
        initData();
         $('#viewMapBtnId').val($('#viewMapBtn').val());

    });

    function initData() {
        var id = '<s:property value="id"/>';

        var mode = "toBeApprovedKachcheryLandList";
        var type = "kachchery";
        $.getJSON('${pageContext.request.contextPath}/common/LandLookupService', {id:id, mode:mode, type:type}, function(data) {
            loadLandList(data.landAssociationDetailsList);
        });
    }


    function loadLandList(landInfo) {

        var opt = '';
        opt += '<thead>' +
                '<tr class="table-header">' +
                '<th class="center-align">' + $('#sel').val() + '</th>' +
                '<th class="center-align">' + $('#ref').val() + '</th>' +
                '<th class="left-align">' + $('#lname').val() + '</th>' +
                '<th class="left-align">' + $('#display').val() + '</th>' +
                '<th class="center-align">1&nbsp;</th>' +
                '<th class="center-align">2&nbsp;</th>' +
                '<th class="center-align">3&nbsp;</th>' +
                '<th class="center-align">4&nbsp;</th>' +
                '<th class="center-align">5&nbsp;</th>' +
                '<th class="center-align">6&nbsp;</th>' +
                '<th class="center-align">7&nbsp;</th>' +

                '</tr>' +
                '</thead>';
        if (landInfo.length > 0) {
            opt += '<tbody>';
            for (var i = 0; i < landInfo.length; i++) {


                opt += '<tr>' +
                        '<td class="center-align"><input  checked title="' + $('#sel').val() + '" type="checkbox" name="landKachcheryList" value="' + landInfo[i].id + '"/></td>' +

                        '<td class="center-align">' + landInfo[i].id + '</td>' +
                        '<td>' + landInfo[i].nameOfTheLand + '</td>' +
                        '<td class="center-align"><input type="button" value="View" onClick="viewLandDetails(\'' + landInfo[i].id + '\')" /></td>';
                if (landInfo[i].alienationMethods != null && landInfo[i].alienationMethods.length > 0) {


                    if (landInfo[i].landPermit == 1) {
                        opt += '<td class="center-align"><input checked title="' + $('#viewTooltipLp').val() + '" type="checkbox" name="amPermitList" value="' + landInfo[i].id + '" /></td>';

                    } else {
                        opt += '<td class="center-align"><input  title="' + $('#viewTooltipLp').val() + '" type="checkbox" name="amPermitList" value="' + landInfo[i].id + '" /></td>';

                    }


                    if (landInfo[i].landGrant == 1) {
                        opt += '<td class="center-align"><input checked title="' + $('#viewTooltipLg').val() + '" type="checkbox" name="amGrantList" value="' + landInfo[i].id + '" /></td>';

                    } else {
                        opt += '<td class="center-align"><input  title="' + $('#viewTooltipLg').val() + '" type="checkbox" name="amGrantList" value="' + landInfo[i].id + '" /></td>';

                    }


                    if (landInfo[i].shortTerm == 1) {
                        opt += '<td class="center-align"><input checked title="' + $('#viewTooltipStl').val() + '" type="checkbox" name="amSTLList" value="' + landInfo[i].id + '" /></td>';

                    } else {
                        opt += '<td class="center-align"><input  title="' + $('#viewTooltipStl').val() + '" type="checkbox" name="amSTLList" value="' + landInfo[i].id + '" /></td>';

                    }


                    if (landInfo[i].longTerm == 1) {
                        opt += '<td class="center-align"><input checked title="' + $('#viewTooltipLtl').val() + '" type="checkbox" name="amLTLList" value="' + landInfo[i].id + '" /></td>';

                    } else {
                        opt += '<td class="center-align"><input  title="' + $('#viewTooltipLtl').val() + '" type="checkbox" name="amLTLList" value="' + landInfo[i].id + '" /></td>';

                    }


                    if (landInfo[i].dep == 1) {
                        opt += '<td class="center-align"><input checked title="' + $('#viewTooltipRd').val() + '" type="checkbox" name="amRDList" value="' + landInfo[i].id + '" /></td>';

                    } else {
                        opt += '<td class="center-align"><input  title="' + $('#viewTooltipRd').val() + '" type="checkbox" name="amRDList" value="' + landInfo[i].id + '" /></td>';

                    }


                    if (landInfo[i].vesting == 1) {
                        opt += '<td class="center-align"><input checked title="' + $('#viewTooltipVo').val() + '" type="checkbox" name="amVOList" value="' + landInfo[i].id + '" /></td>';

                    } else {
                        opt += '<td class="center-align"><input  title="' + $('#viewTooltipVo').val() + '" type="checkbox" name="amVOList" value="' + landInfo[i].id + '" /></td>';

                    }


                    if (landInfo[i].special == 1) {
                        opt += '<td class="center-align"><input checked title="' + $('#viewTooltipSp').val() + '" type="checkbox" name="amSPList" value="' + landInfo[i].id + '" /></td>';

                    } else {
                        opt += '<td class="center-align"><input  title="' + $('#viewTooltipSp').val() + '" type="checkbox" name="amSPList" value="' + landInfo[i].id + '" /></td>';

                    }


                } else {
                    opt += '<td class="center-align"><input  title="' + $('#viewTooltipLp').val() + '" type="checkbox" name="amPermitList" value="' + landInfo[i].id + '" /></td>';
                    opt += '<td class="center-align"><input  title="' + $('#viewTooltipLg').val() + '" type="checkbox" name="amGrantList" value="' + landInfo[i].id + '" /></td>';
                    opt += '<td class="center-align"><input  title="' + $('#viewTooltipStl').val() + '" type="checkbox" name="amSTLList" value="' + landInfo[i].id + '" /></td>';
                    opt += '<td class="center-align"><input  title="' + $('#viewTooltipLtl').val() + '" type="checkbox" name="amLTLList" value="' + landInfo[i].id + '" /></td>';
                    opt += '<td class="center-align"><input  title="' + $('#viewTooltipRd').val() + '" type="checkbox" name="amRDList" value="' + landInfo[i].id + '" /></td>';
                    opt += '<td class="center-align"><input  title="' + $('#viewTooltipVo').val() + '" type="checkbox" name="amVOList" value="' + landInfo[i].id + '" /></td>';
                    opt += '<td class="center-align"><input  title="' + $('#viewTooltipSp').val() + '" type="checkbox" name="amSPList" value="' + landInfo[i].id + '" /></td>';

                }
                opt += '</tr>';
            }
           $('#save-kachchery-land-list').show();
        } else {
            opt += '<tbody>';
            $('#save-kachchery-land-list').hide();
        }
        opt += '</tbody>';
        $('.land-table').html(opt);
        $('.land-table').dataTable({
            "sPaginationType": "full_numbers",
            "bDestroy": true,
            "oLanguage": {
                "sZeroRecords": $('#no-record').val(),
                "sLengthMenu": $('#display').val() + " _MENU_ " + $('#records').val(),
                "sSearch": $('#search').val(),
                "sInfo": $('#showing').val() + " _START_ " + $('#to').val() + " _END_ " + $('#of').val() + " _TOTAL_ " + $('#entries').val(),
                "sInfoEmpty": $('#no-record').val(),
                "oPaginate": {
                    "sFirst": $('#first').val(),
                    "sLast": $('#last').val(),
                    "sNext": $('#next').val(),
                    "sPrevious": $('#previous').val()
                }
            },
            "fnDrawCallback": function() {
                if ($('.dataTables_paginate span span.paginate_button').size()) {
                    $('.dataTables_paginate')[0].style.display = "block";
                } else {
                    $('.dataTables_paginate')[0].style.display = "none";
                }
            }
        });
    }


    function viewLandDetails(landId) {


        var url = '${pageContext.request.contextPath}' + '/viewDetailLandReportByAttachLand.do?landId=' + landId;

        myWindow = window.open(url, '', 'width=980,height=500,scrollbars=yes');
        myWindow.focus();


    }

    function viewLandAssociation(landId) {

        var url = '${pageContext.request.contextPath}' + '/initLandAssociationReport.do?landId=' + landId;

        myWindow = window.open(url, '', 'width=980,height=500,scrollbars=yes');
        myWindow.focus();

    }

    function viewLandMap(id) {


        var url = '${pageContext.request.contextPath}' + '/viewKachcheryMapPopup.do?id=' + id;

        myWindow = window.open(url, '', 'width=980,height=550,scrollbars=yes');
        myWindow.focus();


    }


</script>

<div id="land-registration-module-home-title" class="module-home-title">
    <s:a href="loadKachcheryEditList.do">
        <img src="${pageContext.request.contextPath}/images/interest-party.png" alt="Land Registration">
        <span>
            <s:label value="%{getText('kachchery_land_list.label')}"/>
        </span>
    </s:a>
    <div id="back-button" align="right">
        <s:form><s:submit value="%{getText('back_btn.label')}" action="loadKachcheryEditList"/></s:form>
    </div>
</div>

<div class="page-title">
    <h2><s:label value="%{getText('kachchery_land_list.label')}"/></h2>
</div>

<s:form id="save-kachchery-land-list" name="save-kachchery-land-list" enctype="multipart/form-data"
        method="POST" onsubmit="javascript:return validateFormForInputDataSyntaxErrors('save-kachchery-land-list')">

    <div>

        <fieldset id="land-schedule-form-id" style="border:none;">
            <table class="width-100">

                <tr>
                    <td><s:label value="%{getText('kachchery_list_name.label')}"
                                 cssClass="width-300-px"/></td>
                    <td><s:textfield id="kachchery_list_name" name="kachchery.name" readonly="true"/></td>
                </tr>

                <tr>
                    <td><s:label value="%{getText('description.label')}"/></td>
                    <%--<s:if test="#session.userGroup=='lo'">
                        <td><s:textarea id="discriptionId" name="kachchery.description" cssClass="width-450-px"/></td>
                    </s:if>
                    <s:else>
                        <td><s:textarea id="discriptionId" name="kachchery.description" cssClass="width-450-px"
                                        readonly="true"/></td>
                    </s:else>--%>
                    <td><s:textarea id="discriptionId" name="kachchery.description" cssClass="width-450-px"
                                        readonly="true"/></td>


                </tr>
            </table>
            <br/>

            <s:include value="alienationMethodList.jsp"/>

            <table id="land-table" class="width-100 margin-10-auto table land-table">

            </table>

            <table class="width-100">
                <s:if test="kachchery.comment.length() !=0">
                    <tr>
                        <td><s:label value="%{getText('comments_history.label')}"/></td>
                        <td><s:textarea id="oldCommentId" name="kachchery.comment" cssClass="width-450-px"
                                        readonly="true"/></td>
                    </tr>
                </s:if>
                <tr>
                    <td><s:label value="%{getText('comment.label')}"/></td>
                    <td><s:textarea id="commentId" name="comment" cssClass="width-450-px"/></td>
                </tr>
            </table>

            <s:include value="../../documentUpload.jsp"/>

            <div class="form-button-div right-align">

                <%-- <s:submit action="viewKachcheryMap" value="viewKachcheryMap"/>--%>
                 <input type="button" id="viewMapBtnId" onClick="viewLandMap(<s:property value="id"/>);" />

                <s:if test="#session.userGroup=='lo'">
                    <s:if test="kachcheryMode==4">
                             <s:submit action="attachDocKachchery" value="%{getText('attach.label')}"/>
                    </s:if>
                    <s:else>
                           <s:submit action="editKachchery" value="%{getText('edit.label')}"/>
                             <s:submit action="rejectKachchery" value="%{getText('reject.label')}"/>
                    </s:else>

                </s:if>
                <s:else>
                    <s:submit action="approveKachchery" value="%{getText('approve.label')}"/>
                      <s:submit action="rejectKachchery" value="%{getText('reject.label')}"/>
                </s:else>


                <s:submit cssClass="cancel" action="loadKachcheryTobeApproved" value="%{getText('cancel.label')}"/>



            </div>
        </fieldset>


    </div>

    <s:hidden id="kachcheryId" name="id"/>
</s:form>


<%-- Localization text for data tables --%>
<s:hidden id="display" value="%{getText('display.label')}"/>
<s:hidden id="records" value="%{getText('records.label')}"/>
<s:hidden id="search" value="%{getText('search.label')}"/>
<s:hidden id="no-record" value="%{getText('no_record.label')}"/>
<s:hidden id="showing" value="%{getText('showing.label')}"/>
<s:hidden id="to" value="%{getText('to.label')}"/>
<s:hidden id="of" value="%{getText('of.label')}"/>
<s:hidden id="entries" value="%{getText('entries.label')}"/>
<s:hidden id="first" value="%{getText('first.label')}"/>
<s:hidden id="last" value="%{getText('last.label')}"/>
<s:hidden id="next" value="%{getText('next.label')}"/>
<s:hidden id="previous" value="%{getText('previous.label')}"/>

<s:hidden id="ref" value="%{getText('slmsSerialNumber.label')}"/>
<s:hidden id="lname" value="%{getText('name_of_the_land.label')}"/>

<s:hidden id="viewTooltipLp" value="%{getText('land_permits.label')}"/>
<s:hidden id="viewTooltipLg" value="%{getText('land_grants.label')}"/>
<s:hidden id="viewTooltipStl" value="%{getText('short_term_lease.label')}"/>
<s:hidden id="viewTooltipLtl" value="%{getText('long_term_lease.label')}"/>
<s:hidden id="viewTooltipRd" value="%{getText('release_to_departments.label')}"/>
<s:hidden id="viewTooltipVo" value="%{getText('vesting_order.label')}"/>
<s:hidden id="viewTooltipSp" value="%{getText('special_grant.label')}"/>

<s:hidden id="viewMapBtn" value="%{getText('view_kachchcery_map.label')}"/>
<s:hidden id="sel" value="%{getText('select_kachchery.label')}"/>


